using System;
using System.Globalization;
using Wolfpack.Core.Checks;
using Wolfpack.Core.Interfaces.Entities;
using Wolfpack.Core.Notification;

namespace Wolfpack.Contrib.Checks.Fake
{
    public class FakeCheck : HealthCheckBase<FakeCheckConfig>
    {
        public FakeCheck(FakeCheckConfig config) : base(config)
        {
        }

        public override void Execute()
        {
            var data = HealthCheckData.For(Identity, "Check {0} result is {1}", Identity.Name, _config.Result);
            if (_config.Result.HasValue)
                data.ResultIs(_config.Result.Value);

            Publish(NotificationRequestBuilder.For(_config.NotificationMode, data).Build());
        }

        protected override PluginDescriptor BuildIdentity()
        {
            var resultMsg = _config.Result.HasValue
                                ? _config.Result.Value.ToString(CultureInfo.InvariantCulture)
                                : "[Null]";

            return new PluginDescriptor
            {
                Description = "Fake HealthCheck always returns " + resultMsg,
                Name = "FakeCheck",
                TypeId = new Guid("8206B0A6-21F1-4FCF-BA7A-776C1C5B3ABE")
            };
        }
    }
}